package cn.com.hbhgkj.dao.hibernate;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import cn.com.hbhgkj.dao.CopyrightRegisterationDao;
import cn.com.hbhgkj.model.CopyrightRegisteration;

@Repository("copyrightRegisterationDao")
public class CopyrightRegisterationDaoHibernate extends
		GenericDaoHibernate<CopyrightRegisteration, Long> implements
		CopyrightRegisterationDao {

	public CopyrightRegisterationDaoHibernate() {
		super(CopyrightRegisteration.class);
	}

	public CopyrightRegisteration findBySeriaNum(String seriaNum) {
		Criteria criteria = this.getSession().createCriteria(
				CopyrightRegisteration.class);
		criteria.add(Restrictions.eq("serialNum", seriaNum));

		return criteria.list().size() > 0 ? (CopyrightRegisteration) criteria
				.list().get(0) : null;

	}

	@Override
	public List<CopyrightRegisteration> getAll() {
		Criteria criteria = getSession().createCriteria(
				CopyrightRegisteration.class);
		criteria.addOrder(Order.desc("id")).addOrder(Order.desc("serialNum"))
				.addOrder(Order.desc("copyrighter"))
				.addOrder(Order.desc("productName"))
				.addOrder(Order.desc("contact"))
				.addOrder(Order.desc("phoneNum"))
				.addOrder(Order.desc("mobileNum"))
				.addOrder(Order.desc("email"))
				.addOrder(Order.desc("registDate"));
		return criteria.list();
	}

}
